﻿
@{
    ViewBag.Title = "AccountingPlan";
    Layout = "~/Views/Shared/_Index.cshtml";

    var from = Context.Request.QueryString["from"];
}
<style>
    .toolbar {
        width: 57% !important;
    }

    .gw_num {
        border: 1px solid #dbdbdb;
        width: 44px;
        line-height: 26px;
        overflow: hidden;
        resize: none;
        border-radius: 4px;
        box-shadow: none;
    }

        .gw_num em {
            display: block;
            height: 26px;
            width: 11px;
            float: left;
            color: #7A7979;
            border-right: 1px solid #dbdbdb;
            text-align: center;
            cursor: pointer;
        }

        .gw_num .num {
            display: block;
            float: left;
            text-align: center;
            width: 20px;
            font-style: normal;
            font-size: 14px;
            line-height: 24px;
            border: 0;
        }

        .gw_num em.add {
            float: right;
            border-right: 0;
            border-left: 1px solid #dbdbdb;
        }
</style>
<form name="form1">
    <div class="panel panel-default">
        <div class="panel-heading navb-bg">
            筛选条件
        </div>
        <div style="padding: 2px;padding-right:20px;">
            <table class="form">
                <tr>
                    @if (!(from == "mz"))
                    {
                        <th class="formTitle">长临：</th>
                        <td class="formValue">
                            <select id="yzxz" name="yzxz" class="form-control">
                                <option value="">==全部==</option>
                                <option value="1">临</option>
                                <option value="2">长</option>
                            </select>
                        </td>
                    }
                    <th class="formTitle">执行状态：</th>
                    <td class="formValue">
                        <select id="zxzt" name="zxzt" class="form-control" data-EnumType="EnumJzjhZXZT">
                            <option value="">==全部==</option>
                        </select>
                    </td>
                    <th class="formTitle">关键字：</th>
                    <td class="formValue">
                        <input type="text" class="form-control" id="keyword" placeholder="患者姓名/病历号/门诊号">
                    </td>
                    <th class="formTitle">计划录入时间：</th>
                    <td class="formValue" colspan="2">
                        <input id="kssj" type="text" class="form-control input-wdatepicker" style="width:42%; float:left;" value="@DateTime.Now.ToString("yyyy-MM-01")" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd' })">
                        <span style="margin-left:1%;float:left">—</span>
                        <input id="jssj" type="text" class="form-control input-wdatepicker" style="width:43%; float:left;margin-left:1%;" value="@DateTime.Now.ToString("yyyy-MM-dd")" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd' })">
                    </td>
                    <td class="formValue">
                        <input type="button" class="btn btn-primary btn_search" style="margin-left: 10%;" value="查询">
                    </td>
                </tr>
                <tr class="mzrow">
                    <th class="formTitle">收费状态：</th>
                    <td class="formValue">
                        <select id="sfzt" name="sfzt" class="form-control" data-EnumType="">
                            <option value="">==全部==</option>
                            <option value="1">已收费</option>
                            <option value="2">未收费</option>
                        </select>
                    </td>
                    <th class="formTitle">再收费提醒：</th>
                    <td class="formValue">
                        <div class="gw_num">
                            <em class="jian">-</em>
                            <input type="text" value="" class="num" id="zsftx" />
                            <em class="add">+</em>
                        </div>
                    </td>
                    <th class="formTitle" style="left:-90px">
                        <span style="line-height:26px">剩余次数提醒：</span>
                    </th>
                    <td class="formValue">
                        <div class="gw_num" style="margin-left:-95px">
                            <em class="jian">-</em>
                            <input type="text" value="" class="num" id="sycstx" />
                            <em class="add">+</em>
                        </div>
                    </td>
                    <td class="formValue">
                        <input type="button" class="btn btn-primary btn_searchmz" style="margin-left: -95px;" value="查询" />
                    </td>
                </tr>
            </table>
        </div>
    </div>
    <div class="gridPanel">
        <table id="gridList"></table>
        <div id="gridPager"></div>
    </div>
    <table style="width:400px;height:20px; margin-top:10px;margin-left:10px; float:left; color:#274b6d">
        <tr>
            <td>注：可双击已执行次数大于0的记录查看执行详情</td>
        </tr>
    </table>
</form>
@Html.Partial("_BottomButtonsView", new Newtouch.HIS.Web.Core.Models.BottomButtonViewModel()
{
    ShowKeyList = new int[] { 4, 7, 9 },
    F7Text = "停止",
    F9Text = "导出Excel",
})
<script>
    var from = $.request("from");
    if (!!!from) {
        from = "zy";
    }

    if (from === 'mz') {
        $('#keyword').attr('placeholder', '患者姓名/病历号/门诊号');
        $('.btn_search').css("display", "none");
    }
    else {
        $('#keyword').attr('placeholder', '患者姓名/病历号/住院号');
        $("tr[class^='mzrow']").remove();
    }

    $(function () {

        //执行状态切换 自动触发查询
        $('#yzxz').change(function () {
            $('.btn_search').trigger('click');
        });
        //执行状态切换 自动触发查询
        $('#zxzt').change(function () {
            $('.btn_search').trigger('click');
        });
        //执行收费状态 自动触发查询
        $('#sfzt').change(function () {
            $('.btn_search').trigger('click');
        });

        gridList();
    });

    //关键字回车
    $('#keyword').keydownEnterEvent(function () {
        $('.btn_search,.btn_searchmz').trigger('click');
    })

    //明细
    var $gridList = $("#gridList");
    var gridOptins = {
        url: "/HospitalizationManage/BookkeepInHos/AccountingPlanQuery",
        postData: getSearchPostData(),
        height: from == "mz" ? $(window).height() - 235 : $(window).height() - 205,
        colModel: [
        { label: "jzjhmxId", name: "jzjhmxId", key: true, hidden: true },
        {
            label: "长临", name: "yzxz", width: 30, align: "left", formatter: function (cellvalue, a, b) {
                return cellvalue == "2" ? "长" : (cellvalue == "1" ? "临" : "");
            }, hidden: from == "mz" ? true : undefined
        },
        {
            label: "开单日期", name: "startDate", width: 80, hidden: (from == "mz" ? true : undefined), formatter: function (val) {
                if (!!val) {
                    var date = $.getDate({ date: val });
                    if (date < '2000-01-01') {
                        return '';  //一部分历史数据1970-01-01
                    }
                    return date;
                }
                return "";
            }
        },
        {
            label: "执行状态", name: "zxzt", width: 80, align: "left",
            formatter: function (cellvalue, a, b) {
                return $.enum.getDescByValue("EnumJzjhZXZT", cellvalue);
            }
        },
        { label: "患者姓名", name: "xm", width: 80, align: "left" },
        { label: "病历号", name: "blh", width: 80, align: "left" },
        { label: (from == "mz" ? "门诊号" : "住院号"), name: "mzzyh", width: (from == "mz" ? 100 : 70), align: "left" },
        { label: "收费项目", name: "sfxmmc", width: 180, align: "left" },
        { label: "单次治疗量", name: "zll", width: 75, align: "left" },
        { label: "单位", name: "dw", width: 40, align: "left" },
        { label: "单次数量", name: "sl", width: 60, align: "left" },
        { label: (from == "mz" ? "总次数" : "次数"), name: "zcs", width: 45, align: "left" },
        { label: "已执行", name: "yzxcs", width: 40, align: "left" },
        { label: "剩余次数", name: "sycs", width: 55, align: "left" },
        {
            label: "最后治疗日期", name: "LastEexcutionTime", width: 100, align: "left",
            formatter: "date", formatoptions: { srcformat: 'Y-m-d', newformat: 'Y-m-d' }
        },
            {
                label: "收费日期", name: "sfrq", width: 100, align: "left", hidden: from == "mz" ? undefined : true,
                formatter: "date", formatoptions: { srcformat: 'Y-m-d', newformat: 'Y-m-d' }
            },
        {
            label: "最后操作时间", name: "zhxtzxsj", width: 120, align: "left",
            formatter: "date", formatoptions: { srcformat: 'Y-m-d H:i:s', newformat: 'Y-m-d H:i:s' }
        },
        {
            label: "录入日期", name: "CreateTime", width: 100, align: "left",
            formatter: "date", formatoptions: { srcformat: 'Y-m-d', newformat: 'Y-m-d' }
        },
        { label: "备注", name: "bz", width: 150, align: "left" },
        ],
        multiselect: true,
        pager: "#gridPager",
        sortname: 'CreateTime desc',
        viewrecords: true,
        gridComplete: function () {
            var ids = $("#gridList").getDataIDs();
            for (i = 0; i < ids.length; i++) {
                var rowData = $("#gridList").getRowData(ids[i]);
                if (rowData && rowData.zxzt) {
                    if (rowData.zxzt == "执行中") {
                        $("#" + ids[i]).find("td").addClass('info');
                    }
                    if (rowData.zxzt == "已完成") {
                        $("#" + ids[i]).find("td").addClass('complete');
                    }
                    if (rowData.zxzt == "已停止") {
                        $("#" + ids[i]).find("td").addClass('danger');
                    }
                }
            }
        },
        ondblClickRow: function (rowid) {
            var rowObj = $gridList.jqGrid('getRowData', rowid);
            EditRow(rowObj);
        }
    };
    function gridList() {
        $gridList.dataGrid(gridOptins);
        $('.btn_search,.btn_searchmz').click(function () {
            if ($('#kssj').val() && $('#jssj').val() && ($('#kssj').val() > $('#jssj').val())) {
                $.modalAlert("开始日期不能大于结束日期", 'warning');
                return;
            }
            $gridList.jqGrid('setGridParam',
                {
                    postData: getSearchPostData(),
                    page: 1,
                    url: "/HospitalizationManage/BookkeepInHos/AccountingPlanQuery"
                }).trigger('reloadGrid');
        });
    }
    //查询条件
    function getSearchPostData() {
        var keyword = $("#keyword").val();
        var kssj = $("#kssj").val();
        var jssj = $("#jssj").val();
        var yzxz = $("#yzxz").val();
        var zxzt = $("#zxzt").val();
        var zsftx = $('#zsftx').val();
        var sycstx = $('#sycstx').val();
        var sfzt = $("#sfzt").val();
        return { keyword: keyword, kssj: kssj, jssj: jssj, yzxz: yzxz, zxzt: zxzt, sfzt: sfzt, from: from, zsftx: zsftx, sycstx: sycstx };
    };

    //终止
    function newtouch_event_f7() {
        var jzjhmxIdStr = "";
        var allData = $("#gridList").jqGrid('getRowData_AllLine', true, true);
        $.each(allData, function () {
            if (this.jzjhmxId && this.zxzt !== '已完成' && this.zxzt !== '已停止') {
                jzjhmxIdStr += this.jzjhmxId + ',';
            }
        });
        if (!jzjhmxIdStr) {
            if (allData.length > 0) {
                $.modalAlert("请先选中可停止的记录", 'warning');
            }
            else {
                $.modalAlert("请先选中需停止的记录", 'warning');
            }
            return;
        }
        StopPlan(jzjhmxIdStr);
    }

    function StopPlan(jzjhmxIdStr) {
        //获取选中行Id
        $.najax({
            type: "POST",
            url: "/HospitalizationManage/BookkeepInHos/StopAccountingPlan",
            data: { jzjhmxIdStr: jzjhmxIdStr, from: from },
            dataType: "json",
            success: function (ajaxresp) {
                $.modalAlert(ajaxresp.message, 'success');
                //重新加载
                $('.btn_search').trigger('click');
            },
        });
    }

    //清除操作
    function newtouch_event_f4() {
        $('#gridList').jqGrid("resetSelection");
        $('#gridList').jqGrid("clearGridData");
        $('#kssj').val('@DateTime.Now.ToString("yyyy-MM-01")');
        $('#jssj').val('@DateTime.Now.ToString("yyyy-MM-dd")');
    }

    function EditRow(rowObj) {
        if (rowObj && rowObj.yzxcs > 0) {
            $.modalOpen({
                id: "Details",
                title: "查看执行详情",
                url: "/HospitalizationManage/BookkeepInHos/ViewPlanDetail?keyValue=" + rowObj.jzjhmxId + "&from=" + from + "&zxzt=" + rowObj.zxzt,
                width: "1200px",
                height: "600px",
                btn: null
            });
        }
    }

    //导出Excel 列
    var exportCols = null;
    function newtouch_event_f9() {
        exportCols = new Array();
        var colsChooseSourceArr = new Array();
        $.each(gridOptins.colModel, function () {
            if (!(this.hidden === true)) {
                exportCols.push({ Heading: this.label, Name: this.name, Width: this.width });
                colsChooseSourceArr.push({ Heading: this.label, Name: this.name });
            }
        });
        var url = "/HospitalizationManage/BookkeepInHos/ExcelExportChooseColumns";
        var cols = JSON.stringify(colsChooseSourceArr);
        cols = encodeURIComponent(cols);
        url += "?cols=" + cols;
        $.modalOpen({
            id: "ExcelExportChooseColumns",
            title: "导出Excel",
            url: url,
            width: "600px",
            height: "350px",
            callBack: function (iframeId) {
                //结果
                var restArr = top.frames[iframeId].GetChoosedCols();
                if (!!!restArr || !!!restArr.length || restArr.length == 0) {
                    $.modalAlert("请选择导出列", 'error');
                    return false;
                }
                var isContainFilter = top.frames[iframeId].GetIsContainFilter();
                //关闭选择窗口
                $.modalClose("ExcelExportChooseColumns");
                //
                exportCols = $.jsonWhere(exportCols, function (v) {
                    var matched = false;
                    for (var iIndex = 0; iIndex < restArr.length; iIndex++) {
                        if (restArr[iIndex] == v.Name) {
                            matched = true;
                        }
                    }
                    return matched;
                });
                //导出
                Export(isContainFilter);
            }
        });
    }

    function Export(isContainFilter) {
        var url = "/HospitalizationManage/BookkeepInHos/AccountingPlanExportExcel?r=" + Math.random();
        url += "&keyword=" + $('#keyword').val();
        url += "&kssj=" + $('#kssj').val();
        url += "&jssj=" + $('#jssj').val();
        url += "&yzxz=" + $('#yzxz').val();
        url += "&zxzt=" + $('#zxzt').val();
        url += "&sfzt=" + $('#sfzt').val();
        url += "&zsftx=" + $('#zsftx').val();
        url += "&sycstx=" + $('#sycstx').val();
        url += "&from=" + from;
        url += "&isContainFilter=" + isContainFilter;
        url += "&colStanWidth=" + "70";  //列宽度标准列
        var cols = JSON.stringify(exportCols);
        top.$.cookie('ExportExcelCols', cols, { path: "/" });
        //url += "&cols=" + encodeURIComponent(cols);

        window.open(url);
    }

</script>

<script>
    $(document).ready(function () {
        //加的效果
        $(".add").click(function () {
            var n = $(this).prev().val();
            if (isNaN(parseInt(n))) {
                num = 1;    //add从1开始
            } else {
                var num = parseInt(n) + 1;
            }
            $(this).prev().val(num);
        });
        //减的效果
        $(".jian").click(function () {
            var n = $(this).next().val();
            if (isNaN(parseInt(n)) || parseInt(n) < 1) {
                num = 0;
            } else {
                var num = parseInt(n) - 1;
            }
            $(this).next().val(num);
        });
    });
    var patter_num = /^[0-9]*$/;
    $('#zsftx,#sycstx').keyup(function () {
        var fob = $(this).val();
        if (!patter_num.test(fob)) {
            $.modalAlert("输入值必须为不小于0的整数", 'warning');
            $(this).val("");
            $(this).focus();
            return;
        };
    });
</script>
